BEGIN TRANSACTION;
BEGIN TRY
    -- 业务操作（如更新多个表）
    UPDATE Table1 SET Column1 = @Value1;
    UPDATE Table2 SET Column2 = @Value2;

    COMMIT TRANSACTION;
END TRY
BEGIN CATCH
    DECLARE @ErrorMsg NVARCHAR(4000) = ERROR_MESSAGE();
    IF XACT_STATE() = -1 
        ROLLBACK TRANSACTION;  -- 回滚事务‌:ml-citation{ref="4,7" data="citationList"}
    -- 记录错误日志（包含时间、操作类型）
    INSERT INTO TransactionLog (ErrorMsg, OperationType, LogTime)
    VALUES (@ErrorMsg, 'Update', GETDATE());
    THROW;  -- 重新抛出异常‌:ml-citation{ref="4,7" data="citationList"}
END CATCH;
